/**
 * TokioException.java
 *
 * @author Beatrice Bacelli
 * @author Luca Bedogni
 * @author Silvia Righini
 */
package unibo.lsb.exception;

import java.awt.Component;

import javax.swing.JOptionPane;

public class TokioException extends Exception {

	String msg = "";
	String dialogTitle = "Error";
	int msgType = JOptionPane.ERROR_MESSAGE;

	public TokioException(String msg, String dialogTitle, int msgType) {
		this.msg = msg;
		this.dialogTitle = dialogTitle;
		switch (msgType) {
		case 0:
			this.msgType = JOptionPane.QUESTION_MESSAGE;
			break;
		case 1:
			this.msgType = JOptionPane.INFORMATION_MESSAGE;
			break;
		case 2:
			this.msgType = JOptionPane.WARNING_MESSAGE;
			break;
		default:
			this.msgType = JOptionPane.ERROR_MESSAGE;
			break;
		}
	}

	public TokioException(String msg, String dialogTitle) {
		this.msg = msg;
		this.dialogTitle = dialogTitle;
	}

	public void displayInDialog(Component component) {
		JOptionPane.showMessageDialog(component, this.msg, this.dialogTitle,
				this.msgType);
	}

	public void DisplayErrorInDialog(Component component) {
		if (component != null) {
			JOptionPane.showMessageDialog(component, this.msg,
					this.dialogTitle, JOptionPane.ERROR_MESSAGE);
		} else {
			System.err
					.println("Not showing dialog window, passed component is null");
		}
	}

	/**
	 * @return the msg
	 */
	public String getMsg() {
		return msg;
	}

	/**
	 * @param msg
	 *            the msg to set
	 */
	public void setMsg(String msg) {
		this.msg = msg;
	}

	/**
	 * @return the dialogTitle
	 */
	public String getDialogTitle() {
		return dialogTitle;
	}

	/**
	 * @param dialogTitle
	 *            the dialogTitle to set
	 */
	public void setDialogTitle(String dialogTitle) {
		this.dialogTitle = dialogTitle;
	}

	/**
	 * @return the msgType
	 */
	public int getMsgType() {
		return msgType;
	}

	/**
	 * @param msgType
	 *            the msgType to set
	 */
	public void setMsgType(int msgType) {
		this.msgType = msgType;
	}

}
